package com.imooc.miaosha.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Tuple;

import java.util.HashMap;
import java.util.Set;


public class JedisUtil {


    public static void set(String prefix, String key, String value) {
        RedisPoolConfig.getResource().set(prefix + ":" + key, value);
    }


    public static String get(String prefix, String key) {
        return RedisPoolConfig.getResource().get(prefix + ":" + key);
    }

    public static void setEx(String prefix, String key, String value, Integer ex) {
        RedisPoolConfig.getResource().setex(prefix + ":" + key, ex, value);
    }

    public static void expire(String prefix, String key, Integer time) {
        RedisPoolConfig.getResource().expire(prefix + ":" + key, time);
    }

    public static long zadd(String key, String field, Double value) {
        return RedisPoolConfig.getResource().zadd(field, value, key);
    }

    public static double zincrby(String key, String field, Double value) {
        return RedisPoolConfig.getResource().zincrby(field, value, key);
    }
    public static double zscore(String key, String field) {
        return RedisPoolConfig.getResource().zscore(key,field);
    }
    public static Set<String> zrangeReverse(String key, long start, long end) {
        return RedisPoolConfig.getResource().zrevrange(key, start, end);
    }

    public static Set<Tuple> zrangeReverseWithScores(String key, long start, long end) {
        return RedisPoolConfig.getResource().zrevrangeWithScores(key, start, end);
    }

    public static Long ex(String key, Integer time) {
        return RedisPoolConfig.getResource().expire(key, time);
    }

    public static Long decr(String prefix, String key) {
        return RedisPoolConfig.getResource().decr(prefix + ":" + key);
    }

    public static Long incr(String prefix, String key) {
        return RedisPoolConfig.getResource().incr(prefix + ":" + key);
    }

    public static Long del(String prefix, String key) {
        return RedisPoolConfig.getResource().del(prefix + ":" + key);
    }
}
